import React, { Component } from 'react'

class Toggle extends Component {

    constructor(props) {
        super(props)
        this.state = {isToggleOn: true};
        //this.handleClick = this.handleClick.bind(this)
    }

    handleClick() {
        this.setState(prevState => ({
            isToggleOn: !this.state.isToggleOn
        }))
    }
    render() {
        return (
            <div>
                <button onClick={this.handleClick}>
                  开关  {this.state.isToggleOn ? 'ON' : 'OFF'}
                </button>
            </div>
        )
    }
}

export default Toggle;